package com.web.util;

import com.web.exception.ExceptionEnum;
import com.web.pojo.Result;

/**
 * @Description 统一返回结果集
 * @Author 朱金圣[zhu_js@suixingpay.com]
 * @Date 2019/12/1 9:15
 * @Version 1.0
 */
public class ResultUtil {
    /**
     * @Description 返回成功，传入返回体具体出參
     * @Author zhu_jinsheng[zhu_js@suixingpay.com]
     * @Param object:  数据
     * @return: com.web.pojo.Result
     * @Date 2019/12/8 15:29
     */
    public static Result success(Object object){
        Result result = new Result();
        result.setStatus(200);
        result.setMsg("success");
        result.setData(object);
        return result;
    }

    /**
     * @Description 提供给部分不需要出參的接口
     * @Author zhu_jinsheng[zhu_js@suixingpay.com]
     * @return: com.web.pojo.Result
     * @Date 2019/12/8 15:30
     */
    public static Result success(){
        return success(null);
    }

    /**
     * @Description 自定义错误信息
     * @Author zhu_jinsheng[zhu_js@suixingpay.com]
     * @Param status: 状态码
     * @Param msg:  提示信息
     * @return: com.web.pojo.Result
     * @Date 2019/12/8 15:31
     */
    public static Result error(Integer status, String msg){
        Result result = new Result();
        result.setStatus(status);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    /**
     * 返回异常信息，在已知的范围内
     * @param exceptionEnum
     * @return
     */
    public static Result error(ExceptionEnum exceptionEnum){
        Result result = new Result();
        result.setStatus(exceptionEnum.getStatus());
        result.setMsg(exceptionEnum.getMsg());
        result.setData(null);
        return result;
    }
}
